package org.example.controller;

import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Delete;
import org.example.pojo.*;
import org.example.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/inventory")
public class InventoryController {
    @Autowired
    private InventoryService inventoryService;

    /**
     * 查询库存
     * @return
     */
    @GetMapping("/list")
    public Result<PageBean<Inventory>> list(Integer pageNum,Integer pageSize,String goodsName,Integer category){
        PageBean<Inventory> inventory = inventoryService.list(pageNum,pageSize,goodsName,category);
        return Result.success(inventory);
    }

    /**
     * 分页查询待入库的订单列表
     */
    @GetMapping("/stockIn/list")
    public Result<PageBean<StockInVo>> stockInList(Integer pageNum,Integer pageSize,String orderNo,String startTime,String endTime){
        PageBean<StockInVo> list = inventoryService.stockInList(pageNum,pageSize,orderNo,startTime,endTime);
        return Result.success(list);
    }

    /**
     * 入库
     */
    @PostMapping("/stockIn")
    public Result stockIn(@RequestBody stockInDto stockInDto){
        inventoryService.stockIn(stockInDto);
        return Result.success();
    }

    /**
     * 新增出库单
     */
    @PostMapping("/outbound/add")
    public Result<String> outboundAdd(@RequestBody OutboundDto dto){
        String orderId = inventoryService.outboundAdd(dto);
        return Result.success(orderId);
    }


    /**
     * 出库单列表
     * @return
     */
    @GetMapping("/outbound/list")
    public Result<PageBean<OutboundOrderVo>>outboundList(int pageNum, int pageSize, String orderId, Integer orderType, String startTime, String endTime){
        return Result.success(inventoryService.outboundList(pageNum, pageSize, orderId, orderType, startTime, endTime));
    }


    /**
     * 出库单详情
     */
    @GetMapping("/outbound/detail/{orderId}")
    public Result<OutboundOrderVo> outboundDetail(@PathVariable String orderId){
        OutboundOrderVo detail = inventoryService.outboundDetail(orderId);
        return Result.success(detail);
    }

    /**
     * 审批出库单
     */
    @PostMapping("/outbound/approve")
    public Result<Void> approve(@RequestBody Map<String,Object> map){
        inventoryService.approve(map.get("orderId").toString());
        return Result.success();
    }

    /**
     * 删除出库单
     */
    @DeleteMapping("/outbound/delete/{orderId}")
    public Result<Void> delete(@PathVariable String orderId){
        inventoryService.delete(orderId);
        return Result.success();
    }
//    /**
//     * 出库列表
//     */
//    @GetMapping("/stockOut/list")
//    public Result<PageBean<StockOutVo>> stockOutList(Integer pageNum,Integer pageSize,String goodsName,String startTime,String endTime){
//        PageBean<StockOutVo> list = inventoryService.stockOutList(pageNum,pageSize,goodsName,startTime,endTime);
//        return Result.success(list);
//    }
//
//    /**
//     * 出库详情
//     */
//    @GetMapping("/detail/{id}")
//    public Result<StockOutVo> detail(@PathVariable Integer id){
//        StockOutVo detail = inventoryService.detail(id);
//        return Result.success(detail);
//    }
//
//    /**
//     * 出库
//     */
//    @PostMapping("/stockOut")
//    public Result<Void> stockOut(@RequestBody Map<String,Object> map){
//        inventoryService.stockOut(map);
//        return Result.success();
//    }


}
